﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using FrameworkLib.Configuration;

namespace GestionePolveriImporter.Configuration
{
    class RedirectConfigurationHandler : FLibConfigurationSection<RedirectConfigurationHandler>
    {
        [ConfigurationProperty("", IsDefaultCollection = true, IsKey = false, IsRequired = true)]
        public RedirectCollection Redirects
        {
            get
            {
                return base[""] as RedirectCollection;
            }

            set
            {
                base[""] = value;
            }
        }
    }

    class RedirectCollection : FLibConfigurationCollection<RedirectElement>
    {
        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }
    }

    [ConfigurationSectionNameAttribute("redirect")]
    class RedirectElement : FLibConfigurationElement
    {
        [ConfigurationProperty("filePattern", IsRequired = true, IsKey = true)]
        public string FilePattern
        {
            get { return base["filePattern"] as string; }
            set { base["filePattern"] = value; }
        }

        [ConfigurationProperty("url", IsRequired = true, IsKey = false)]
        public string RedirectUrl
        {
            get { return base["url"] as string; }
            set { base["url"] = value; }
        }

        [ConfigurationProperty("Maps", IsDefaultCollection = false),
         ConfigurationCollection(typeof(FLibConfigurationCollection<MapElement>), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
        public FLibConfigurationCollection<MapElement> Maps
        {
            get { return (FLibConfigurationCollection<MapElement>)this["Maps"]; }
        }
    }
}
